var Poll = function() {
	return {
		init: function() {
			animateResults();
			jQuery("#quickPollAnswer li:first input[type='radio']").attr("checked","checked"); 
			jQuery("#btnSubmit").click(function() {
                jQuery("#" + PollData.QuickPollClientId).css("cursor", "wait"); //show wait cursor inside Poll div while processing
                jQuery("#btnSubmit").attr("disabled", "true") //disable the Vote button while processing
                
                var pollId = PollData.PollId;
                var choiceId =  jQuery("input[name='vote']:checked").val(); //get the checked Choice
               
                AjaxPro.call({
		            url: PollData.AjaxGatewayUrl,
		            method: 'UpdatePollCount',
		            params: {
		            	pollId: pollId,
		            	choiceId: choiceId,
		            	culture: PollData.Culture
	            	},
		            success: function(value) {
		                if (value) {
		                    jQuery("#" + PollData.QuickPollClientId).css("cursor", "default"); //remove the wait cursor
		                    jQuery("#btnSubmit").attr("disabled", "false") //enable the Vote button
		                    jQuery('#quickPollAnswer').css('display', 'none');
		                    jQuery("#" + PollData.ResultPollPanelClientID).fadeOut("fast").html(value).fadeIn("fast", function(){ animateResults(); });
		                } 
		            }
		        });
            });
		}
	};
}();
jQuery(document).ready(Poll.init);

function animateResults() {
	jQuery("div[id$=" + PollData.ResultPollPanelClientID + "] img").each(function() {
		var percentage = $(this).attr("val");
		jQuery(this).css({width: "0%"}).animate({width: percentage}, 'slow'); 
	});
}